﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Selling : System.Web.UI.Page
{
    Connectdbnour con = new Connectdbnour();
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = GlobalClass.Client;
        Label3.Text = GlobalClass.DT;
    }
    
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (CheckBox2.Checked == true)
        {
            if (con.connect().State != ConnectionState.Open)
            {
                con.connect().Open();
                SqlCommand sqlcom = new SqlCommand();
                SqlCommand sqlcom1 = new SqlCommand();
                sqlcom.Connection = con.connect();
                sqlcom.CommandType = CommandType.Text;
                sqlcom1.Connection = con.connect();
                sqlcom1.CommandType = CommandType.Text;
                sqlcom.CommandText = "select brandname, vd,color,sph,cyl,axis,bc,diam,store1,store2 from lens where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + " order by color";
                sqlcom1.CommandText = "select brandname, vd,color,pck,sph,cyl,axis,bc,diam,store1,store2 from box where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + " order by color";
                GridView2.DataSource = sqlcom.ExecuteReader();
                GridView2.DataBind();
                con.connect().Close();
                con.connect().Open();
                GridView1.DataSource = sqlcom1.ExecuteReader();
                GridView1.DataBind();
                //con.connect().Close();
                //con.connect().Open();
                //SqlDataAdapter da1 = new SqlDataAdapter("(select brandname from lens where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + ") union (select brandname from box where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + ")", con.connect());
                //DataTable dt1 = new DataTable();
                //DataView dv1;
                //da1.Fill(dt1);
                //dv1 = dt1.DefaultView;
                //for (int i = 0; i < con.Countbrand(); i++)
                //{
                //    DropDownList9.Items.Add(dv1[i][0].ToString());
                //}
            }
            con.connect().Close();
        }
        else if (CheckBox2.Checked == false)
        {
            if (con.connect().State != ConnectionState.Open)
            {
                con.connect().Open();
                SqlCommand sqlcom = new SqlCommand();
                SqlCommand sqlcom1 = new SqlCommand();
                sqlcom.Connection = con.connect();
                sqlcom.CommandType = CommandType.Text;
                sqlcom1.Connection = con.connect();
                sqlcom1.CommandType = CommandType.Text;
                sqlcom.CommandText = "select brandname, vd,color,sph,cyl,axis,bc,diam,store1,store2 from lens where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + " and color='" + DropDownList10.SelectedItem.ToString() + "'";
                sqlcom1.CommandText = "select brandname, vd,color,pck,sph,cyl,axis,bc,diam,store1,store2 from box where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + " and color='" + DropDownList10.SelectedItem.ToString() + "'";                
                GridView2.DataSource = sqlcom.ExecuteReader();
                GridView2.DataBind();
                con.connect().Close();
                con.connect().Open();
                GridView1.DataSource = sqlcom1.ExecuteReader();
                GridView1.DataBind();
                //con.connect().Close();
                //con.connect().Open();
                //SqlDataAdapter da1 = new SqlDataAdapter("(select brandname from lens where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + " and color='" + DropDownList10.SelectedItem.ToString() + "') union (select brandname from box where sph=" + Convert.ToDouble(DropDownList4.SelectedItem.ToString()) + " and cyl=" + Convert.ToDouble(DropDownList5.SelectedItem.ToString()) + " and axis=" + Convert.ToDouble(DropDownList6.SelectedItem.ToString()) + " and bc=" + Convert.ToDouble(DropDownList7.SelectedItem.ToString()) + " and diam=" + Convert.ToDouble(DropDownList8.SelectedItem.ToString()) + " and color='" + DropDownList10.SelectedItem.ToString() + "')", con.connect());
                //DataTable dt1 = new DataTable();
                //DataView dv1;
                //da1.Fill(dt1);
                //dv1 = dt1.DefaultView;
                //for (int i = 0; i < con.Countbrand(); i++)
                //{
                //    DropDownList9.Items.Add(dv1[i][0].ToString());
                //}
            }
            con.connect().Close();
        //    String[] array = new String[12];
        //    array = con.codetoname(Convert.ToInt32(TextBox1.Text));
        }
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        
    }
    protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox3.Checked == true)
        {
            DropDownList12.Enabled = false;
            DropDownList14.Enabled = false;
            TextBox2.Enabled = true;
        }
        else if (CheckBox3.Checked == false)
        {
            DropDownList12.Enabled = true;
            DropDownList14.Enabled = true;
            TextBox2.Enabled = false;
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        try
        {
            if (CheckBox3.Checked == true)
            {
                con.Addfclens(DropDownList15.SelectedItem.ToString(), Label3.Text, Convert.ToInt32(Label1.Text), DropDownList9.SelectedItem.ToString(), DropDownList13.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList10.SelectedItem.ToString(), 1, 1, Convert.ToDouble(DropDownList4.SelectedItem.ToString()), Convert.ToDouble(DropDownList5.SelectedItem.ToString()), Convert.ToDouble(DropDownList6.SelectedItem.ToString()), Convert.ToDouble(DropDownList7.SelectedItem.ToString()), Convert.ToDouble(DropDownList8.SelectedItem.ToString()), Convert.ToInt16(TextBox2.Text), Convert.ToInt16(TextBox3.Text));
            }
            else if (CheckBox3.Checked == false)
            {
                if (DropDownList14.SelectedItem.ToString() != "All")
                {
                    con.Addfclens(DropDownList15.SelectedItem.ToString(), Label3.Text, Convert.ToInt32(Label1.Text), DropDownList9.SelectedItem.ToString(), DropDownList13.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList10.SelectedItem.ToString(), Convert.ToInt16(DropDownList12.SelectedItem.ToString()), Convert.ToInt16(DropDownList14.SelectedItem.ToString()), Convert.ToDouble(DropDownList4.SelectedItem.ToString()), Convert.ToDouble(DropDownList5.SelectedItem.ToString()), Convert.ToDouble(DropDownList6.SelectedItem.ToString()), Convert.ToDouble(DropDownList7.SelectedItem.ToString()), Convert.ToDouble(DropDownList8.SelectedItem.ToString()), 1, Convert.ToInt16(TextBox3.Text));
                }
                else
                {
                    con.Addfclens(DropDownList15.SelectedItem.ToString(), Label3.Text, Convert.ToInt32(Label1.Text), DropDownList9.SelectedItem.ToString(), DropDownList13.SelectedItem.ToString(), DropDownList11.SelectedItem.ToString(), DropDownList10.SelectedItem.ToString(), Convert.ToInt16(DropDownList12.SelectedItem.ToString()), Convert.ToInt16(DropDownList12.SelectedItem.ToString()), Convert.ToDouble(DropDownList4.SelectedItem.ToString()), Convert.ToDouble(DropDownList5.SelectedItem.ToString()), Convert.ToDouble(DropDownList6.SelectedItem.ToString()), Convert.ToDouble(DropDownList7.SelectedItem.ToString()), Convert.ToDouble(DropDownList8.SelectedItem.ToString()), 1, Convert.ToInt16(TextBox3.Text));
                }          
            }

        }
        catch (Exception ex)
        {
            
            Label2.Text=ex.Message;
        }
        Response.Redirect("Selling.aspx");
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        con.fctoclens();
        Response.Redirect("Selling.aspx");
    }
}